#include <stdio.h>  
#include <string.h>  
#include <stdlib.h>  
  
int main() {  
    char* input = "8.8.13.10,219.141.136.10,202.106.0.20";
    // char* input = "8.8.8.10,219.141.136.10";  
    char ip1[20] = {0};
    char ip2[20] = {0};

    // 首先找到逗号的位置
    char *commaPos = strchr(input, ',');  

    // 计算第一个IP地址的长度（不包括逗号）
    size_t ip1Length = commaPos - input;  

    printf("ip1 Length = %ld \n", ip1Length);

    // 复制第一个IP地址到ip1
    strncpy(ip1, input, ip1Length);  
    ip1[ip1Length] = '\0'; // 确保字符串正确终止  

    commaPos++;

    char *dns_tmp_tmp = strchr(commaPos, ',');

    if (dns_tmp_tmp == NULL) {
        strncpy(ip2, commaPos, sizeof(ip2));
    } else {
        ip1Length = dns_tmp_tmp - commaPos;
        printf("ip2 Length = %ld \n", ip1Length);
        strncpy(ip2, commaPos, ip1Length);
        ip2[ip1Length] = '\0';
    }

    // 现在ip1和ip2分别包含了两个IP地址  
    printf("IP1: %s\n", ip1);  
    printf("IP2: %s\n", ip2);  

    return 0;  
}
